package com.dm.frontend.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dm.common.utils.DubboUtil;
import com.dm.dto.sort.DmItemInfo;
import com.dm.module.DmArea;
import com.dm.module.DmItemType;
import com.dm.sort.service.SortService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("sort")
public class SortController {


    @Reference(url = DubboUtil.DUBBO_URL_SORT,version = DubboUtil.VERSION_1, group = DubboUtil.GROUP_NAME)
    private SortService sortService;


    /**
     * 查询所有城市和分类信息
     * @param model
     * @return
     */

    @RequestMapping("get/sort")
    public String getAll(Model model){
        List<DmArea> dmAreas = sortService.getAll();
        model.addAttribute("dmAreas",dmAreas);
        List<DmItemType> dmItems = sortService.sortAll();
        model.addAttribute("dmItems",dmItems);
        return "sort/webdamai";
    }


    /**
     * 根据城市 分类查询 以及分页功能
     * @param pageSize
     * @param pageNum
     * @param areaId
     * @param itemType1Id
     * @return
     */
    @RequestMapping("list/page/{pageSize}/{pageNum}/{areaId}/{itemType1Id}")
    @ResponseBody
        public PageInfo<DmItemInfo> listPage(@PathVariable("pageSize") int pageSize,
                                             @PathVariable("pageNum") int pageNum,
                                             @PathVariable("areaId")  Long areaId ,
                                             @PathVariable("itemType1Id")  Long itemType1Id){
        PageInfo<DmItemInfo> page =sortService.listPage(pageNum,pageSize,areaId,itemType1Id);
        return page;
    }




}
